Skip to content

Fix/isv submchid input coercion - #46

Closed
txiao8586 wants to merge 3 commits into
wop-platform:mainfrom
txiao8586:fix/isv-submchid-input-coercion
Closed

txiao8586 wants to merge 3 commits into
wop-platform:mainfrom
txiao8586:fix/isv-submchid-input-coercion

Conversation

@txiao8586

@txiao8586 txiao8586 commented Oct 28, 2026 •

Copy link
Copy Markdown

What does this PR do?

Spec compliance

Checklist

  • Tests updated and passing locally with the repository's own CI commands
  • No modification to golden test vectors (crypto-vectors.json is read-only)
  • Conventional Commits format used

Sourcery 总结

支持经过验证的 ISV 子商户身份传递,同时在未指定子商户时保留现有请求行为。

新功能:

  • 支持通过 sub_mch_id 请求参数和执行参数传入可选的 ISV 子商户身份,并在签名后的请求中包含 x-wop-sub-mch-id 请求头。
  • 允许通过 extra_headers 传入等效的子商户身份;如果多个来源提供了冲突的值,则拒绝请求。

错误修复:

  • 防止无效、非字符串、包含控制字符、空白字符或非 ASCII 字符,以及超长的子商户 ID 被静默强制转换或用于签名。
  • 未提供子商户身份或其值为空白时,保留与原先完全一致的请求头和签名。

文档:

  • 在英文和中文 README 文件中说明 ISV D-13 子商户身份的使用方式、验证规则、签名行为和网关前置条件。

测试:

  • 增加对子商户请求头签名、验证、输入来源处理、入站行为、执行时传递以及向后兼容性的测试覆盖。
Original summary in English

Summary by Sourcery

Support validated ISV sub-merchant identity propagation while preserving existing request behavior when no sub-merchant is specified.

New Features:

  • Add optional ISV sub-merchant identity support through the sub_mch_id request and execute parameters, including signed x-wop-sub-mch-id headers.
  • Allow equivalent sub-merchant identity input through extra_headers while rejecting conflicting duplicate sources.

Bug Fixes:

  • Prevent invalid, non-string, control-character, whitespace-containing, non-ASCII, and oversized sub-merchant IDs from being silently coerced or signed.
  • Preserve byte-identical request headers and signatures when sub-merchant identity is omitted or blank.

Documentation:

  • Document ISV D-13 sub-merchant identity usage, validation rules, signing behavior, and gateway prerequisites in English and Chinese README files.

Tests:

  • Add coverage for sub-merchant header signing, validation, input-source handling, inbound behavior, execute propagation, and backward compatibility.

xiaotao and others added 3 commits October 27, 2026 20:06
ISV D-13:build_request/execute 新增 sub_mch_id,签名前写入 x-wop-sub-mch-id 并自动纳入 signedHeaders;不传/空白 = 应用自身身份,头缺席,头集合与签名与旧版逐字节一致(AC-20)。extra_headers 携带该头等价参数,双来源同传即拒。校验:可打印 ASCII、无内部空白、trim 后 ≤128 字符。补 test_submchid.py。

Co-Authored-By: Claude Code <noreply@anthropic.com>
审查 F1:extra_headers 分支 `str(value)` 把 None 强转成 "None" 并静默
入签错误子商户身份;参数路径对 int 等非 str 抛裸 TypeError。

- resolve_sub_mch_id 增 isinstance(str) 守卫(None 仍=未设置)
- extra_headers 的 x-wop-sub-mch-id 原值进同一校验链,去掉 str() 强转
- 测试:非 str 参数/extra_headers 均 ConfigurationError;None → 头缺席、
  签名与基线逐字节一致

验证:python -m pytest --cov=wop_sdk --cov-branch --cov-fail-under=98
→ 全绿,覆盖率 98.89%。

Co-Authored-By: Claude Code <noreply@anthropic.com>
- README zh/en:前置改为「网关已部署 D-13」并删灰度措辞;trim 措辞精确化为
  「仅首尾空格可 trim,控制字符即便在首尾也拒」;补充非字符串入参行为
- tests:新增入向不消费用例(响应额外携带未入签 x-wop-sub-mch-id 仍通过)

验证:pytest --cov 全绿(98.89%)。

Co-Authored-By: Claude Code <noreply@anthropic.com>
@txiao8586
txiao8586 requested a review from im47cn as a code owner October 28, 2026 11:25
@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1ce41dc3-8d37-4496-9669-e8597234141a
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

评审者指南

端到端实现 ISV D-13 子商户身份输入:经过验证的值会被规范化,并在签名前作为 x-wop-sub-mch-id 插入;两个请求 API 均支持该输入,也安全支持通过 extra_headers 提供该值;同时包含广泛的回归和边界测试,并在省略该值时保持原有行为。

ISV 子商户请求签名时序图

sequenceDiagram
    participant Caller
    participant Client
    participant Resolver as resolve_sub_mch_id
    participant Signer
    participant Gateway

    Caller->>Client: build_request 或 execute,传入 sub_mch_id
    Client->>Resolver: resolve_sub_mch_id(value)
    alt 有效的非空白值
        Resolver-->>Client: 去除首尾空白后的子商户 ID
        Client->>Client: 在签名前添加 x-wop-sub-mch-id
        Client->>Signer: 使用 signedHeaders 对请求签名
        Signer-->>Client: 已签名的请求
        Client->>Gateway: 发送带有请求头和签名的请求
    else 省略或为空白
        Resolver-->>Client: None
        Client->>Signer: 对不包含子商户请求头的请求签名
    else 输入无效
        Resolver-->>Client: ConfigurationError
    end
Loading

子商户输入来源解析流程图

flowchart TD
    A[子商户身份输入] --> B{是否同时提供参数和 extra_headers?}
    B -->|是| C[ConfigurationError]
    B -->|否| D[resolve_sub_mch_id]
    D --> E{是否为有效的可打印 ASCII 值?}
    E -->|否| C
    E -->|去除首尾空白后为空| F[省略 x-wop-sub-mch-id]
    E -->|有效| G[在签名前插入 x-wop-sub-mch-id]
    G --> H[将请求头纳入 signedHeaders]
Loading

文件级变更

变更 详情 文件
为请求构造和执行添加经过验证的 ISV 子商户身份支持。
  • 在构造请求和单次执行 API 中引入 sub_mch_id。
  • 通过配置错误验证类型、可打印 ASCII 字符、空白字符、修剪和长度。
  • 解析来自 extra_headers 的等效输入,拒绝重复来源,并防止不安全的类型强制转换。
  • 在签名前添加 x-wop-sub-mch-id,使其包含在已签名请求头中;缺少该值或值为空白时,保持原有行为逐字节不变。
src/wop_sdk/client.py
说明 D-13 子商户身份规范和网关前置条件。
  • 为两个请求 API 添加英文和中文用法示例。
  • 说明规范化、拒绝规则、签名行为、ISV 适用范围以及与 AC-20 的兼容性。
  • 提示条件签名要求网关部署 D-13。
README.en.md
README.md
增加对签名、API 参数传递、验证和向后兼容性的测试覆盖。
  • 验证已签名请求头的包含情况,以及不同请求体和加密级别下的密码学有效性。
  • 测试参数与请求头输入的等效性、重复来源拒绝、传入请求头处理以及 execute 参数传递。
  • 覆盖控制字符和非 ASCII 输入、空白字符、长度边界、非字符串值、空白值,以及旧请求头保持不变的情况。
tests/test_config.py
tests/test_submchid.py

提示与命令

与 Sourcery 交互

  • 触发新的评审: 在拉取请求中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的评审意见。
  • 根据评审意见创建 GitHub issue: 回复评审意见,请 Sourcery 根据该意见创建 issue。也可以回复评审意见并输入 @sourcery-ai issue 来创建 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置输入 @sourcery-ai,即可随时生成标题。也可以在拉取请求中评论 @sourcery-ai title,以便随时重新生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中所需位置输入 @sourcery-ai summary,即可随时在该位置生成 PR 摘要。也可以在拉取请求中评论 @sourcery-ai summary,以便随时重新生成摘要。
  • 生成评审者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时重新生成评审者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已处理所有评论且不想再看到它们,这会很有用。
  • 忽略所有 Sourcery 评审: 在拉取请求中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 评审。如果你想从头开始进行新一轮评审,这尤其有用——别忘了评论 @sourcery-ai review 来触发新的评审!

自定义使用体验

访问你的控制面板,即可:

  • 启用或停用评审功能,例如 Sourcery 生成的拉取请求摘要、评审者指南等。
  • 更改评审语言。
  • 添加、删除或编辑自定义评审说明。
  • 调整其他评审设置。

获取帮助

Original review guide in English

Reviewer's Guide

Implements ISV D-13 sub-merchant identity input end to end: validated values are normalized, inserted as x-wop-sub-mch-id before signing, exposed through both request APIs, and safely supported via extra_headers, with extensive regression and boundary coverage preserving legacy behavior when omitted.

Sequence diagram for ISV sub-merchant request signing

sequenceDiagram
    participant Caller
    participant Client
    participant Resolver as resolve_sub_mch_id
    participant Signer
    participant Gateway

    Caller->>Client: build_request or execute with sub_mch_id
    Client->>Resolver: resolve_sub_mch_id(value)
    alt valid nonblank value
        Resolver-->>Client: trimmed sub-merchant ID
        Client->>Client: add x-wop-sub-mch-id before signing
        Client->>Signer: sign request with signedHeaders
        Signer-->>Client: signed request
        Client->>Gateway: send request with header and signature
    else omitted or blank
        Resolver-->>Client: None
        Client->>Signer: sign request without sub-merchant header
    else invalid input
        Resolver-->>Client: ConfigurationError
    end
Loading

Flow diagram for sub-merchant input source resolution

flowchart TD
    A[Sub-merchant identity input] --> B{Both parameter and extra_headers provided?}
    B -->|Yes| C[ConfigurationError]
    B -->|No| D[resolve_sub_mch_id]
    D --> E{Valid printable ASCII value?}
    E -->|No| C
    E -->|Blank after trimming| F[Omit x-wop-sub-mch-id]
    E -->|Valid| G[Insert x-wop-sub-mch-id before signing]
    G --> H[Include header in signedHeaders]
Loading

File-Level Changes

Change Details Files
Adds validated ISV sub-merchant identity support to request construction and execution.
  • Introduces sub_mch_id on build and one-shot execution APIs.
  • Validates type, printable ASCII, whitespace, trimming, and length with configuration errors.
  • Resolves equivalent input from extra_headers, rejects duplicate sources, and prevents unsafe coercion.
  • Adds x-wop-sub-mch-id before signing so it is included in signed headers; preserves prior byte-identical behavior when absent or blank.
src/wop_sdk/client.py
Documents the D-13 sub-merchant identity contract and gateway prerequisites.
  • Adds English and Chinese usage examples for both request APIs.
  • Documents normalization, rejection rules, signing behavior, ISV scope, and AC-20 compatibility.
  • Warns that gateway D-13 deployment is required for conditional signing.
README.en.md
README.md
Adds coverage for signing, API propagation, validation, and backward compatibility.
  • Verifies signed-header inclusion and cryptographic validity across body and encryption levels.
  • Tests parameter/header equivalence, duplicate-source rejection, inbound header handling, and execute propagation.
  • Covers control and non-ASCII input, whitespace, length boundaries, non-string values, blank values, and unchanged legacy headers.
tests/test_config.py
tests/test_submchid.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@changeset-bot

changeset-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 77e2a25

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好——我已审查你的更改,整体看起来很棒!

Sourcery 评估

需要人工审核。 已签名的 x-wop-sub-mch-id 用于为请求选择子商户上下文;如果发送了错误的 ID,网关可能会以错误的商户身份执行业务操作或持久化记录。回滚可以阻止此后继续使用该请求头,但无法撤销已经执行的操作或已创建的记录。


Sourcery 对开源项目免费——如果你喜欢我们的评审,欢迎分享 ✨
Original comment in English

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. The signed x-wop-sub-mch-id selects the sub-merchant context for a request; if the wrong ID is sent, the gateway may perform business actions or persist records under the wrong merchant. Reverting removes the header behavior going forward but cannot undo actions or records already created.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@txiao8586 txiao8586 closed this Oct 28, 2026
@txiao8586
txiao8586 deleted the fix/isv-submchid-input-coercion branch October 31, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant